import {User} from "../../../../entity/User";
/**
 * Created by enixjin on 1/10/18.
 */
import {UserService} from "../../../../service/userService";
import {AbstractDataAction} from "../../AbstractDataAction";
import {AbstractUserAction} from "../AbstractUserAction";
import {AbstractUserRESTAction} from "../AbstractUserRESTAction";
import {UserCreateCompleteAction} from "../data/UserCreateCompleteAction";
import {UserCreateRESTAction} from "../rest/UserCreateRESTAction";


export class UserCreateAction extends AbstractUserAction {

    constructor(public userService: UserService, public payload: User) {
        super();
    }

    getRestAction(): AbstractUserRESTAction {
        return new UserCreateRESTAction(this.payload, this.userService, this.getLocalKey());
    }

    getDataAction(local): AbstractDataAction {
        return new UserCreateCompleteAction(this.loadFromLocal(local));
    }

    updateLocal(local): void {
        local.get(this.getLocalKey()).unshift(this.payload);
    }

    loadFromLocal(local): any {
        // no id for new created
        // return this.payload;
    }
}
